package com.itheima.wemedia.controller;


import com.itheima.common.vo.PageResultVo;
import com.itheima.common.vo.ResultVo;
import com.itheima.core.controller.AbstractCoreController;
import com.itheima.wemedia.dto.WmMaterialPageRequestDto;
import com.itheima.wemedia.dto.WmNewsContentNodeDto;
import com.itheima.wemedia.dto.WmNewsDtoSave;
import com.itheima.wemedia.dto.WmNewsPageReqDto;
import com.itheima.wemedia.pojo.WmNews;
import com.itheima.wemedia.service.WmNewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.security.PublicKey;
import java.util.Map;

/**
 * @description <p>自媒体图文内容信息</p>
 *
 * @version 1.0
 * @package com.itheima.wemedia.controller
 */
@Api(value="WmNewsController",tags = "自媒体图文内容信息")
@RestController
@RequestMapping("/news")
public class WmNewsController extends AbstractCoreController<WmNews> {

    private WmNewsService wmNewsService;

    @Autowired
    public WmNewsController(WmNewsService wmNewsService) {
        super(wmNewsService);
        this.wmNewsService=wmNewsService;
    }


    /**
     * 分页查询
     * @param wq
     * @return
     */
    @PostMapping("/list")
    @ApiOperation("分页查询")
    public PageResultVo<WmNews> findPage(@RequestBody WmNewsPageReqDto wq){

        PageResultVo<WmNews>  pageResult = wmNewsService.findPage(wq);

       return pageResult;
    }

    /**
     * 发布文章
     * @param draft
     * @param dto
     * @return
     */
    @PostMapping("/submit")
    public ResultVo<Integer> submit(String draft, @RequestBody WmNewsDtoSave dto){

        Integer list = wmNewsService.submit(Boolean.valueOf(draft),dto);

        return ResultVo.ok(list);
    }

    /**
     * 根据id查询
     * @param newId
     * @return
     */
    @GetMapping("/one/{newId}")
    @ApiOperation("这是编辑功能")
    public  ResultVo<WmNews> findByPageId(@PathVariable (value = "newId") int newId){

        WmNews  news =   wmNewsService.getById(newId);
        return ResultVo.ok(news);
    }


    /**
     * 根据id删除
     */
    @GetMapping("/del_news/{newdele_ID}")
    @ApiOperation("根据id删除文章内容")
    public ResultVo<WmNews> deleteById(@PathVariable (value = "newdele_ID") int newdele_ID){

         wmNewsService.deleteById(newdele_ID);

         return ResultVo.ok();
    }

    /**
     * 文章的上下架
     * @return
     */
    @ApiOperation("文章的上下架")
    @PostMapping("/down_or_up")
    public ResultVo downUp(@RequestBody Map<String,Integer> paramsMap){

        wmNewsService.downUp(paramsMap);
        return ResultVo.ok();
    }




}

